package gms.distriblaw;

/**
 * Created by IntelliJ IDEA.
 * User: Anton Dunaev
 * Date: 18.09.2007
 * Time: 13:33:41
 */
public class NormalDistribLaw extends DistribLaw
{
    protected double mu;
    protected double sigma;
    protected boolean is_left_bound = false;
    protected double left_bound;
    protected boolean is_right_bound = false;
    protected double right_bound;


    public NormalDistribLaw( double mu, double sigma )
    {
        this.mu = mu;
        this.sigma = sigma;
    }

    public NormalDistribLaw( double mu, double sigma, double bound, boolean is_left_or_right)
    {
        this.mu = mu;
        this.sigma = sigma;
        if( is_left_or_right )
        {
            this.left_bound = bound;
            this.is_left_bound = true;
        }else
        {
            this.right_bound = bound;
            this.is_right_bound = true;
        }
    }

    public NormalDistribLaw( double mu, double sigma, double left_bound, double right_bound)
    {
        this.mu = mu;
        this.sigma = sigma;
        if( left_bound > right_bound )
        {
            this.left_bound = right_bound;
            this.right_bound = left_bound;
        }else
        {
            this.left_bound = left_bound;
            this.right_bound = right_bound;
        }
        this.is_left_bound = true;
        this.is_right_bound = true;
    }

    
    public double getRand()
    {
        double res = mu + sigma*rnd.nextGaussian();
        if( is_left_bound )
        {
            if( is_right_bound )
            {
                while( (res<left_bound) | (res>right_bound) )
                    res = mu + sigma*rnd.nextGaussian();
            }else
            {
                while( res<left_bound )
                    res = mu + sigma*rnd.nextGaussian();   
            }
        }else
            if( is_right_bound )
            {
                while( res>right_bound )
                    res = mu + sigma*rnd.nextGaussian();
            }
        return  res;
    }
}
